﻿#ifndef HANLDDATA_H
#define HANLDDATA_H

#include <QObject>
#include <QThread>
#include <QTimer>
#include <QSettings>

#define DATA_TEST 1

#if  DATA_TEST
#include "hidapi.h"
#endif

class HanldData : public QThread
{
    Q_OBJECT
public:
    explicit HanldData(QObject *parent = NULL);
    virtual ~HanldData();

    void initData();


    static HanldData * gestance();
    int init_hotplug_sock();

    bool initHandl();

    int readData();

    int readCurrentData();
    int readHeartData();
    int readMcuData();
    int readMcuClearData();

    int writeData(int type,int lens);

    void setCurrentValue(QString nums);
    int getCurrentValue();
signals:
    void sigCurrentData(int nums);
    void sigAddCurrentData(int nums);
    void sigRemoveDevice();
    void sigAddDevice();
    void sigAddCurrentDevice();
    void sigRemoveCurrentDevice();
    void sigAddCurrentComDevice();
    void sigRemoveCurrentComDevice();

public slots:
    void onReadTimeData();
    void onAddTimeDevice();

    void onRemoveimeDevice();
    void onSigAddCurrentDevice();

    void onSigRemoveCurrentDevice();
    void onAddTimeComDevice();
    void onRemoveimeComDevice();

    void onSigAddCurrentComDevice();

    void onSigRemoveCurrentComDevice();
protected:
    void run();


private:
    bool m_isRun;
#if  DATA_TEST
    hid_device *m_handle;
#endif
    unsigned short m_vendor_id;
    unsigned short m_product_id;

    QTimer * m_timer;

    QTimer * m_addTimer;
    QTimer * m_removeTimer;

    QSettings * m_settings;
    QString m_docParh;
    QString m_docParhFile;


    QTimer * m_addComTimer;
    QTimer * m_removeComTimer;
};

#endif // HANLDDATA_H
